package bdz.projects.lavender.cms.model
{
	import flash.events.EventDispatcher;

	public class UserData extends EventDispatcher
	{
		private var _local:XML;
		private static var instance:UserData;
		public function UserData(se:SingletonEnforcer)
		{
			super();
		}
		public static function getUser(defXML:XML = null):UserData{
			
			if(!instance){
				instance = new UserData(new SingletonEnforcer());
				instance.initialize(defXML);
			}
			return instance;
		}
		private function initialize(xm:XML):void{
			var arr:XMLList = xm.children();
			_local = new XML("<"+xm.name().toString().split("::")[1]+"/>");
			for each(var axm:XML in arr){
				_local[axm.name().toString().split("::")[1]] = axm.toString();
			}
		}
		public function get username():String{
			return _local.Email.toString();
		}
		public function set username(str:String):void{
			_local.Email = new XML("<Email>"+str+"</Email>");
		}
		public function get password():String{
			return _local.Password.toString();
		}
		public function set password(str:String):void{
			_local.Password = new XML("<Password>"+str+"</Password>");
		}
		public function get firstName():String{
			return _local.FirstName.toString();
		}
		public function set firstName(str:String):void{
			_local.FirstName = new XML("<FirstName>"+str+"</FirstName>");
		}
		public function get lastName():String{
			return _local.LastName.toString();
		}
		public function set lastName(str:String):void{
			_local.LastName = new XML("<LastName>"+str+"</LastName>");
		}
		public function get address1():String{
			return _local.Address1.toString();
		}
		public function set address1(str:String):void{
			_local.Address1 = new XML("<Address1>"+str+"</Address1>");
		}
		public function get address2():String{
			return _local.Address2.toString();
		}
		public function set address2(str:String):void{
			_local.Address2 = new XML("<Address2>"+str+"</Address2>");
		}
		public function get suburb():String{
			return _local.Suburb.toString();
		}
		public function set suburb(str:String):void{
			_local.Suburb = new XML("<Suburb>"+str+"</Suburb>");
		}
		public function get state():String{
			return _local.State.toString();
		}
		public function set state(str:String):void{
			_local.State = new XML("<State>"+str+"</State>");
		}
		public function get country():String{
			return _local.Country.toString();
		}
		public function set country(str:String):void{
			_local.Country = new XML("<Country>"+str+"</Country>");
		}
		/**
		 * READ ONLY
		 */
		public function get profileID():String{
			return _local.ProfileID.toString();
		}
		public function get appID():String{
			return _local.ApplicationID.toString();
		}
		public function get roleID():String{
			return _local.RoleID.toString();
		}
		public function get sessionKeys():Object{
			return {key1:_local.Rnd1.toString(), key2:_local.Rnd2.toString()};
		}
		/**
		 * METHODS
		 */
		public function toXML():XML{
			return _local;
		}
		
	}
}
/**
 * @private
 * 
 */
internal class SingletonEnforcer{}